00001 00002 bool GUICommandManager::CanUndo() const 00003 { 00004 00005 return ((int)m_undoList.size() > 0); 00006 } 00007 00008 bool GUICommandManager::CanRedo() const 00009 { 00010 00011 return ((int)m_redoList.size() > 0); 00012 } 00013 00014 int GUICommandManager::getUndoLevel() const 00015 { 00016 return m_nUndoLevel; 00017 } 00018 00019 void GUICommandManager::setUndoLevel(int newValue) 00020 { 00021 m_nUndoLevel = newValue; 00022 } 00023 00024 bool GUICommandManager::IsDirty() const 00025 { 00026 return (m_nCleanCount != 0); 00027 } 00028 00029 Command* GUICommandManager::getLastUndoCommand() const 00030 { 00031 return m_undoList.back(); 00032 } 00033 00034 Command* GUICommandManager::getLastRedoCommand() const 00035 { 00036 return m_redoList.back(); 00037 } 00038 00039 void GUICommandManager::DoCommand(Command* pCommand) 00040 { 00041 ClearRedoList(); 00042 00043 if (pCommand->execute()) 00044 AddUndo(pCommand); 00045 00046 } 00047 00048 void GUICommandManager::Undo() 00049 { 00050 if (CanUndo()) 00051 { 00052 m_nCleanCount--; 00053 Command* pCommand = m_undoList.back(); 00054 m_undoList.pop_back(); 00055 if (pCommand->unexecute()) 00056 AddRedo(pCommand); 00057 else 00058 delete pCommand; 00059 } 00060 } 00061 00062 void GUICommandManager::Redo() 00063 { 00064 if (CanRedo()) 00065 { 00066 m_nCleanCount++; 00067 Command* pCommand = m_redoList.back(); 00068 m_redoList.pop_back(); 00069 if (pCommand->execute()) 00070 AddUndo(pCommand); 00071 else 00072 delete pCommand; 00073 } 00074 } 00075 00076 void GUICommandManager::Clear() 00077 { 00078 ClearUndoList(); 00079 ClearRedoList(); 00080 } 00081 00082 00083 void GUICommandManager::SetClean() 00084 { 00085 m_nCleanCount = 0; 00086 } 00087 00088 void GUICommandManager::AddUndo(Command* pCommand) 00089 { 00090 if ((int)m_undoList.size() >= m_nUndoLevel) 00091 { 00092 delete m_undoList.front(); 00093 m_undoList.pop_front(); 00094 } 00095 00096 m_undoList.push_back(pCommand); 00097 00098 00099 if (m_nCleanCount < 0 && m_redoList.size() > 0) 00100 m_nCleanCount = m_undoList.size() + m_redoList.size() + 1; 00101 else 00102 m_nCleanCount++; 00103 00104 00105 } 00106 00107 void GUICommandManager::AddRedo(Command* pCommand) 00108 { 00109 m_redoList.push_back(pCommand); 00110 } 00111 00112 void GUICommandManager::ClearUndoList() 00113 { 00114 ClearCommandList(&m_undoList); 00115 } 00116 00117 void GUICommandManager::ClearRedoList() 00118 { 00119 ClearCommandList(&m_redoList); 00120 } 00121 00122 void GUICommandManager::ClearCommandList(CommandList* pList) 00123 { 00124 CommandList::iterator it; 00125 for (it = pList->begin(); it != pList->end(); it++) 00126 delete *it; 00127 pList->erase(pList->begin(), pList->end()); 00128 } 00129 00130
1.4.6-NO